<?php echo $header; ?>
<div class="container">
	<div class="alert-wrap">
		<div class="alert-position" id="forgotten-a-u"></div>
		<div class="alert-position" id="forgotten-a-e"></div>	
	</div>
<div class="row">
	<div class="col-lg-4 col-lg-offset-4 col-md-6 col-md-offset-3 col-sm-6 col-sm-offset-3 col-xs-6 col-xs-offset-3 forgotten-body b-s-b">
		<form action="" id="form-forgotten">
			<div class="form-group has-feedback input-margin">
				<span class="glyphicon glyphicon-user form-control-feedback icon-pos-font"></span>
				<input type="text" name="username" id="forgottenusername" class="input-bg form-control b-s-b" placeholder="用户名">
			</div>
			<div class="form-group has-feedback input-margin">
				<span class="glyphicon glyphicon-envelope form-control-feedback icon-pos-font"></span>
				<input type="text" name="email" id="forgottenemail" class="input-bg form-control b-s-b" placeholder="邮箱地址">
			</div>
			<div class="input-margin input-margin-more">
				<a href="javascript:void(0);" class="btn btn-primary btn-padding b-s-b center-block" id="forgottensendemail">发送电子邮件</a>
			</div>
		</form>
	</div>
</div>
</div>
<?php echo $footerout;?>
<script>
	$(document).ready(function(){
		var username,email,info;
    	var targetusername = $("#forgotten-a-u");
    	var targetemail = $("#forgotten-a-e");
		$("#forgottenusername").on("blur",function(){
				username = $(this).val();
				
				if(!username_vel(username,targetusername)){
					return false;
				};
		});
		$("#forgottenemail").on("blur",function(){
			email = $(this).val();
			
			if(!email_vel(email,targetemail)){
				return false;
			}
	});
		$("#forgottensendemail").on("click",function(){
			username = $("#forgottenusername").val();
			email = $("#forgottenemail").val();
			if(!username_vel(username,targetusername)){
					return false;
				};
			if(!email_vel(email,targetemail)){
				return false;
			};
			var forminfo=$("#form-forgotten").serialize();
			$.ajax({
				type:"POST",
				dataType:"json",
				url:"<?php echo $sendmailforpassword; ?>",
				data:forminfo,
				beforesend: function () {
					targetusername.html(warninghtml+"正在发送邮件，请稍后！</div>");
				},
				success: function (data){
					if(data === 1) {
						targetusername.html(warninghtml+"该用户名不存在！</div>");
						return false;
					}else if(data === 2) {
						targetemail.html(warninghtml+"该邮箱不存在！</div>");
						return false;
					}else if(data === true){
						targetemail.html(warninghtml+"邮件发送成功</div>");
						var url = "<?php echo $loginurl ?>";
						countDown(3,url,targetusername);
					}else{
						targetusername.html(warninghtml+data+"</div>");
					}
				}
		});
	});
});
</script>
<?php echo $footer; ?>